<template>
  <div id="app">

    <router-view/>

  </div>
</template>

<script>
  import store from "./store/index";
  import plugin from "./util/plugin";
  import pluginAuto from "./plugins/auto/index";
  export default {
    name:"name",
    created() {
      this.register()
      .then(()=>{
        return plugin.tryRun("auto");
      })
      .then((plugin_open)=>{
        // louie_plugin,运行自动计算用户积分插件并且返回积分余额
        if(plugin_open) {
          pluginAuto.auto(this.$sysinfo.uid)
          .then((data)=>{
            store.commit("setMember",data);
          });
        } else {
          this.getMember();
        }
      });
      this.getSetting();
    },
    methods:{
      /**
       * 注册
       */
      register(){
        return this.$url("member/register",{
          uid:this.$sysinfo.uid
        });
      },
      /**
       * 获取用户信息
       */
      getMember(){
        this.$url("member/getMember",{
          uid:this.$sysinfo.uid
        })
        .then((res)=>{
          if(res.data.status === "success"){
            store.commit("setMember",res.data.data);
          }
        });
      },
      /**
       * 获取配置
       */
      getSetting(){
        this.$url("setting/easyFind",{
          return:["currency_name","web_name","web_icon","web_description","show_help","help"]
        })
        .then((res)=>{
          if(res.data.status === "success"){
            if(!this.$sysinfo.develop){
              this.setShare(res.data.data);
            }
            store.commit("setSetting",res.data.data);
          }
        });
      },
      /**
       * 设置分享
       */
      setShare(data_data){
        let data = {
          title:data_data.web_name,
          desc:data_data.web_description,
          link:this.$sysinfo.share_url,
          imgUrl:data_data.web_icon_url
        }
        this.$wx.ready(()=>{
          this.$wx.updateAppMessageShareData(data);
          this.$wx.updateTimelineShareData(data);
          this.$wx.onMenuShareTimeline(data);
          this.$wx.onMenuShareAppMessage(data);
        });
      }
    }
  }
</script>

<style lang="less">
    .children{
        position: fixed;
        background: #F6F6F6;
        z-index:11;
        top:0;
        width: 375px;
    }
</style>

<style lang="stylus">
body,html
  height 100%
#app
  font-family Avenir, Helvetica, Arial, sans-serif
  -webkit-font-smoothing antialiased
  -moz-osx-font-smoothing grayscale
  font-size 14px
  color #000
  background #F6F6F6
  height 100%
</style>
